@extends('Admin.layout.blank')

@section('body')
<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span class="c-gray en">&gt;</span> 产品列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>

	<div class="Hui-article">
		<article class="cl pd-20">

			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<a class="btn btn-primary radius" onclick="goods_add('添加商品','{{ route('goodsadd') }}' ,',','1200','600')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加商品</a></span>
			</div>



			<div class="mt-10">
				<table class="table table-border table-bordered table-bg table-hover table-sort">
				<thead>
					<tr class="text-c">
						<th width="40">ID</th>
						<th width="60">商品名</th>
						<th width="40">品牌</th>
						<th width="40">类别</th>
						<th width="40">价格</th>
						<th width="80">商品图</th>
						<th width="40">点击量</th>
						<th width="40">状态</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<tbody>
				@foreach($goods as $v)
				@php
				$pid = $v->types->pid;
				$type = DB::table('shop_goods_types')->select('type_name')->where('id', $pid)->first();
				@endphp
					<tr class="text-c va-m">
						<td>{{ $v->id }}</td>
						<td>{{ $v->goods_name }}</td>
						<td>{{ $v->brands->brand_name }}</td>
						<td>{{ $type->type_name }}--{{ $v->types->type_name }}</td>
						<td>{{ $v->price }}</td>
						<td>
							<img width="60px" class="product-thumb" src="http://oydt3ttm3.bkt.clouddn.com/{{ $v->goods_pic }}">
						</td>

						<td >{{ $v->click_num }}</td>
						<td class="td-status">
								@if($v->status == 0)
									<span class="label label-success radius">
										在售中
									</span>
								@elseif($v->status == 1)
									<span class="label label-defaunt radius">
										已卖完
									</span>
								@elseif($v->status == 2)
									<span class="label label-defaunt radius">
										已下架
									</span>
								@endif
						</td>
						<td class="td-manage">


						@if($v->status == 0)
								<a style="text-decoration:none" onClick="good_stop(this, {{ $v->id }})" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>

								<a style="text-decoration:none" class="ml-5" onClick="good_detail('商品详情','{{ route('goodsdetail', ['id' => $v->id]) }}' ,',','1200','600')" href="javascript:;" title="查看详情"><i class="Hui-iconfont">&#xe620;</i></a>
							@if($v->promate == 0)
								<a style="text-decoration:none" onClick="do_sales('设置促销','{{ route('goodssales', ['id' => $v->id]) }}' ,',','1000','600')" href="javascript:;" title="设置促销"><i class="Hui-iconfont">&#xe638;</i></a>
							@elseif($v->promate == 1)
								<a style="text-decoration:none" onClick="goods_delsales(this, {{ $v->id }})" href="javascript:;" title="取消促销"><i class="Hui-iconfont">&#xe616;</i></a>
							@endif
								<a style="text-decoration:none" class="ml-5" onClick="goods_edit('编辑商品', '{{ route('goodsedit', ['id' => $v->id]) }}' ,',','1200','600')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>

								<a style="text-decoration:none" class="ml-5" href="javascript:;" onClick="add_pic('添加图片', '{{ route('goodspic', ['id' => $v->id]) }}' ,',','1000','600')" title="添加图片"><i class="Hui-iconfont">&#xe612;</i></a>

								<a style="text-decoration:none" class="ml-5" href="javascript:;" onclick="add_attr('添加商品属性', '{{ route('goodsaddattr', ['id' => $v->id]) }}' ,',','1000','600')" title="添加不同规格属性"><i class="Hui-iconfont">&#xe61f;</i></a>


						    	<a style="text-decoration:none" class="ml-5" href="javascript:;" onclick="good_image('图片列表', '{{ route('goodsimages', ['id' => $v->id]) }}' ,',','1200','600')" title="显示此款产品的图片"><i class="Hui-iconfont">&#xe6f9;</i></a>
									@node('AdminLoop_create')
						    	<a style="text-decoration:none" class="ml-5"  onClick="add_pic('加入轮播图','{{ route('AdminLoop.create', ['id' => $v->id]) }}','1000','600')" title="加入轮播图" title="加入轮播图"><i class="Hui-iconfont">&#xe613;</i></a>
									@endnode

						    	<a style="text-decoration:none" class="ml-5" onClick="good_del(this, {{ $v->id }})" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
						@elseif($v->status == 1)

								<a style="text-decoration:none" class="ml-5" onClick="good_del(this, {{ $v->id }})" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>

						@elseif($v->status == 2)

								<a style="text-decoration:none" onClick="good_start(this, {{ $v->id }})" href="javascript:;" title="上架"><i class="Hui-iconfont">&#xe6dc;</i></a>

								<a style="text-decoration:none" class="ml-5" onClick="good_detail('商品详情','{{ route('goodsdetail', ['id' => $v->id]) }}' ,',','1200','600')" href="javascript:;" title="查看详情"><i class="Hui-iconfont">&#xe620;</i></a>

								<a style="text-decoration:none" class="ml-5" onClick="goods_edit('编辑商品', '{{ route('goodsedit', ['id' => $v->id]) }}' ,',','1200','600')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>

								<a style="text-decoration:none" class="ml-5" href="javascript:;" onClick="add_pic('添加图片', '{{ route('goodspic', ['id' => $v->id]) }}' ,',','1000','600')" title="添加图片"><i class="Hui-iconfont">&#xe612;</i></a>

								<a style="text-decoration:none" class="ml-5" href="javascript:;" onclick="add_attr('添加商品属性', '{{ route('goodsaddattr', ['id' => $v->id]) }}' ,',','1000','600')" title="添加不同规格属性"><i class="Hui-iconfont">&#xe61f;</i></a>


						    	<a style="text-decoration:none" class="ml-5" href="javascript:;" onclick="good_image('图片列表', '{{ route('goodsimages', ['id' => $v->id]) }}' ,',','1200','600')" title="显示此款产品的图片"><i class="Hui-iconfont">&#xe6f9;</i></a>
									@node('AdminLoop_create')
						    	<a style="text-decoration:none" class="ml-5" onClick="add_pic('加入轮播图','{{ route('AdminLoop.create', ['id' => $v->id]) }}','1000','600')" title="加入轮播图"><i class="Hui-iconfont">&#xe613;</i></a>
									@endnode
						    	<a style="text-decoration:none" class="ml-5" onClick="good_del(this, {{ $v->id }})" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
						@endif
					    </td>
					</tr>
				@endforeach
				</tbody>
				</table>
			</div>
		</article>
	</div>
</section>
@endsection

@section('footer-js')

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{ asset('AdminPublic/lib/My97DatePicker/4.8/WdatePicker.js') }}"></script>
<script type="text/javascript" src="{{ asset('AdminPublic/lib/datatables/1.10.0/jquery.dataTables.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('AdminPublic/lib/laypage/1.2/laypage.js') }}"></script>
<script type="text/javascript">
$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	  // {"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":false,"aTargets":[0,6]}// 制定列不参与排序
	]
});

// layer.confirm('您是如何看待前端开发？', {
//   btn: ['重要','奇葩'] //按钮
// }, function(){
//   layer.msg('的确很重要', {icon: 1});
// }, function(){
//   layer.msg('也可以这样', {
//     time: 20000, //20s后自动关闭
//     btn: ['明白了', '知道了']
//   });
// });



/*设置促销*/
function do_sales(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*显示所有图片*/
function good_image(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*查看商品详情*/
function good_detail(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*添加商品不同属性*/
function add_attr(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*添加商品图片*/
function add_attr(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*添加商品*/
function goods_add(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*添加商品图片*/
function add_pic(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*编辑*/
function goods_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*删除*/
function good_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("delgoods")}}',
			data: 'id='+id,

			success:function (msg) {

				//删除失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}

				//删除成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});
					$(obj).parents("tr").remove();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}


/*上架*/
function good_start(obj,id){
	layer.confirm('确认要上架吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("goodsstart")}}',
			data: 'id='+id,

			success:function (msg) {

				//上架失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}

				//上架成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});

					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="good_stop(this,{{$v->id}})" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">在售中</span>');
					$(obj).remove();
					location.reload();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}

/*下架*/
function good_stop(obj,id){
	layer.confirm('确认要下架吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("goodsstop")}}',
			data: 'id='+id,

			success:function (msg) {

				//上架失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}

				//上架成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});

					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="good_start(this, {{$v->id}})" href="javascript:;" title="上架"><i class="Hui-iconfont">&#xe6dc;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
					$(obj).remove();
					location.reload();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}


/*取消促销*/
function goods_delsales(obj,id){
	layer.confirm('确认要取消促销吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("delsales")}}',
			data: 'id='+id,

			success:function (msg) {

				//删除失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}

				//删除成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});
					location.reload();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}

</script>
<!--/请在上方写此页面业务相关的脚本-->

@endsection
